using System;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using Dapasoft.Internal.MVP.Presenter;
using Dapasoft.Internal.MVP.View._12.TEMPLATE.CONTROLTEMPLATES;

namespace Dapasoft.Internal.MVP.View.UI.WebParts.DapasoftTelerikORM
{
    /// <summary>
    /// DapasoftTelerikORM is a class, which demonstrates ability to create web part
    /// bound to the Telerik Rad ORM.
    /// </summary>
    public class DapasoftTelerikORM : System.Web.UI.WebControls.WebParts.WebPart
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="DapasoftTelerikORM"/> class.
        /// </summary>
        public DapasoftTelerikORM()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        #endregion //Constructors

        #region Methods

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that
        /// use composition-based implementation to create any child controls they
        /// contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            try
            {
                this.Controls.Clear();

                GridUserControl gridUserControl = (GridUserControl)this.Page.LoadControl("/_controltemplates/DapasoftTelerikORM/GridUserControl.ascx");

                ScopePresenter presenter = new ScopePresenter();

                gridUserControl.Presenter = presenter;

                this.Controls.Add(gridUserControl);
            }
            catch (Exception ex)
            {
                // Put the error messsage locally on the page
                string errMessage = ex.GetType().ToString() + ": " + ex.Message;
                this.Controls.Add(new LiteralControl(errMessage));
            }
        }

        #endregion // Methods
    }
}
